<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML>
<html>
<head>
<title>Client</title>
<%@include file="/WEB-INF/css.jsp" %>
<%@include file="/WEB-INF/javascript.jsp" %>
<style>
</style>
<script>
$(document).ready(function(){
	$('#CreatePersonalClientButton').button().click(function(){
		$('#PersonalClientDialog').dialog("open");
	});
	// Ajax search clients by names.  This will also empty the Clients Container and rebuild the list.
	// The result will not have limit of clients returned.
	$('#SearchPersonalButton').button().click(function(){
		$.ajax({
			url:"/AjaxSearchPersonalClientName",
			type:"GET",
			dataType:"json",
			data:{
				"keywords":$('#SearchPersonalClient').val()
			},
			success:function(data,status,xhr){
				var clients=data.data;
				var clientsContainer=$('#ClientsContainer');
				clientsContainer.empty();

				for(var i=0;i<clients.length;i++){
					var clientName = (clients[i].Name==undefined?"":clients[i].Name);
		            var email = (clients[i].Email==undefined?"":clients[i].Email);
					if (clientName.length > 15){
						clientName = clientName.substring(0,15) + '...';
					}
					if (email.length>28){
						email = email.substring(0,28) + '...';
					}
					clientsContainer.append('<div class="ClientCard">'+
					'<div class="ClientCardInfo"><span class="kheader" style="font-size:1.2em">Name: <a href="/GetPersonalClient?clientId='+clients[i].clientId+'">'+clientName+'</span></a><br/>'+
					'<span class="kheader">Client No:</span> '+clients[i].ClientNumber+'<br/>'+
					'<span class="kheader">Home Phone:</span> '+(clients[i].HomePhone==undefined?"":clients[i].HomePhone)+'<br/>'+
					'<span class="kheader">Cell Phone:</span> '+(clients[i].CellPhone==undefined?"":clients[i].CellPhone)+'<br/>'+
					'<span class="kheader">Work Phone:</span> '+(clients[i].WorkPhone==undefined?"":clients[i].WorkPhone)+'<br/>'+
					'<span class="kheader">Email:</span> '+email+'<br/></div>'+
					'<div class="ClientCardContact"><span class="kheader">Date In:</span> '+(clients[i].DateIn==undefined?"":clients[i].DateIn)+'<br/>'+
					'<span class="kheader">Date Completed:</span> '+(clients[i].DateCompleted==undefined?"":clients[i].DateCompleted)+'<br/>'+
					'<span class="kheader">Fee:</span> $'+(clients[i].Fee==undefined?"":clients[i].Fee)+'<br/>'+
					'<span class="kheader">Method Of Payment:</span> '+(clients[i].MethodOfPayment==undefined?"":clients[i].MethodOfPayment)+'<br/>'+
					'<span class="kheader">Fee Collected:</span> $'+(clients[i].FeeCollected==undefined?"":clients[i].FeeCollected)+'<br/>'+
					'<span class="kheader">Date Collected:</span> '+(clients[i].DateCollected==undefined?"":clients[i].DateCollected)+'</div>'+
					'<div class="ClientCardNumbers"><span class="kheader">No. Of Returns EFiled:</span> '+(clients[i].NumberOfReturnsEFiled==undefined?"":clients[i].NumberOfReturnsEFiled)+'<br/>'+
					'<span class="kheader">Date EFiled.:</span> '+(clients[i].DateEFiled==undefined?"":clients[i].DateEFiled)+'<br/>'+
					'<span class="kheader">No. Of Returns Paper Filed:</span> '+(clients[i].NumberOfReturnsPaperFiled==undefined?"":clients[i].NumberOfReturnsPaperFiled)+'<br/>'+
					'<span class="kheader">Date Filed:</span> '+(clients[i].DateFiled==undefined?"":clients[i].DateFiled)+'</div>'+
					'</div>');
				}
			},
			error:function(xhr,status,error){
				alert('Error:'+error);
			}
		});
	});
    
	var createClientTimeout;
	function stopCreateClient(){
		clearInterval(createClientTimeout);
	}
		// Mass Create Client
		$('#MassCreateClient').button().click(function(){
			createClientTimeout=setInterval(function(){
				$.ajax({
				url:"/SavePersonalClient",
				type:"POST",
				dataType:"json",
				data:{
					"ClientNumber":new Date().getTime(),
					"FirstName":"John"+new Date().getTime(),
					"LastName":"Lam",
					"Fee":"100",
					"Accountant":"agdwcm0taXN0ch4LEgRVc2VyIhQxODU4MDQ3NjQyMjAxMzkxMjQxMQw"
				}
			});},300);
		});

	// Load all clients
	$.ajax({
		url:"/AjaxGetRecentPersonalClients",
		type:"GET",
		dataType:"json",
		success:function(data,status,xhr){
			var clients=data.data;
			var clientsContainer=$('#ClientsContainer');
			for(var i=0;i<clients.length;i++){
				var clientName = (clients[i].Name==undefined?"":clients[i].Name);
	            var email = (clients[i].Email==undefined?"":clients[i].Email);
				if (clientName.length > 15){
					clientName = clientName.substring(0,15) + '...';
				}
				if (email.length>28){
					email = email.substring(0,28) + '...';
				}

				clientsContainer.append('<div class="ClientCard">'+
				'<div class="ClientCardInfo"><span class="kheader" style="font-size:1.2em">Name: <a href="/GetPersonalClient?clientId='+clients[i].clientId+'">'+clientName+'</span></a><br/>'+
				'<span class="kheader">Client No:</span> '+clients[i].ClientNumber+'<br/>'+
				'<span class="kheader">Home Phone:</span> '+(clients[i].HomePhone==undefined?"":clients[i].HomePhone)+'<br/>'+
				'<span class="kheader">Cell Phone:</span> '+(clients[i].CellPhone==undefined?"":clients[i].CellPhone)+'<br/>'+
				'<span class="kheader">Work Phone:</span> '+(clients[i].WorkPhone==undefined?"":clients[i].WorkPhone)+'<br/>'+
				'<span class="kheader">Email:</span> '+email+'<br/></div>'+
				'<div class="ClientCardContact"><span class="kheader">Date In:</span> '+(clients[i].DateIn==undefined?"":clients[i].DateIn)+'<br/>'+
				'<span class="kheader">Date Completed:</span> '+(clients[i].DateCompleted==undefined?"":clients[i].DateCompleted)+'<br/>'+
				'<span class="kheader">Fee:</span> $'+(clients[i].Fee==undefined?"":clients[i].Fee)+'<br/>'+
				'<span class="kheader">Method Of Payment:</span> '+(clients[i].MethodOfPayment==undefined?"":clients[i].MethodOfPayment)+'<br/>'+
				'<span class="kheader">Fee Collected:</span> $'+(clients[i].FeeCollected==undefined?"":clients[i].FeeCollected)+'<br/>'+
				'<span class="kheader">Date Collected:</span> '+(clients[i].DateCollected==undefined?"":clients[i].DateCollected)+'</div>'+
				'<div class="ClientCardNumbers"><span class="kheader">No. Of Returns EFiled:</span> '+(clients[i].NumberOfReturnsEFiled==undefined?"":clients[i].NumberOfReturnsEFiled)+'<br/>'+
				'<span class="kheader">Date EFiled.:</span> '+(clients[i].DateEFiled==undefined?"":clients[i].DateEFiled)+'<br/>'+
				'<span class="kheader">No. Of Returns Paper Filed:</span> '+(clients[i].NumberOfReturnsPaperFiled==undefined?"":clients[i].NumberOfReturnsPaperFiled)+'<br/>'+
				'<span class="kheader">Date Filed:</span> '+(clients[i].DateFiled==undefined?"":clients[i].DateFiled)+'</div>'+
				'</div>');
			}
		},
		error:function(xhr,status,error){
			//alert('Error:'+error);
		}
	});
});
</script>
</head>
<body>
<%@include file="/WEB-INF/personalclientnavigation.jsp" %>
<div class="ClientListContainer" style="margin-bottom:10px;margin-top:-20px;">
<h2>RECENTLY CREATED PERSONAL CLIENT LIST</h2>
<div class="ClientActionsContainer" style="float:left;width:100%;margin:0 0 0 18px">
<button id="CreatePersonalClientButton">Create Personal Client</button>
<input type="text" id="SearchPersonalClient" name="SearchPersonalClient" size="80" maxlength="255"/><button id="SearchPersonalButton">Search</button>
<!--<button id="MassCreateClient">Mass Create Client</button>
<button id="StopMassCreateClient" onclick="stopCreateClient();">Stop Mass Create Client</button>-->
<%@include file="/WEB-INF/personalclientdialog.jsp" %>
</div>
<div id="ClientsContainer">
</div>
</div>
</body>
</html>